# 字典是什么?
# dict
# {} "键":"值"   别的语言键值对数据
# dic = {"key":"value",1:2,2:3}
# 键:必须是可哈希(不可变的数据类型),并且是唯一的
# 值: 任意

# 字典的无序的,python3.6版本以上 默认了咱们定义顺序,python3.5以下是随机显示
# 字典是可变的,增加,删除,修改,查看 其他操作
# dic = {"key":1,1:123,False:True,(1,2,3):"abc",1:[1,3,4]}
#           0101   0102                          0102
# print(dic)



# 字典怎么用?
# dic = {"a":"b","b":"c"}
# 增:
# dic.setdefault("c","aaa")
# print(dic)

# dic.setdefault("a","aaa")
# print(dic)

# print(dic.setdefault("D"))
# 先去字典查看咱们要添加的键存不存在
# 如果键在字典中存在就不填加,如果要是不存在就添加

# dic["s"] = "ssss"   # dic[键] = 值
# print(dic)

# 删:
# dic = {"a":"b","b":"c"}
# print(dic.pop("a"))   #通过键删除  pop具有返回值,返回的被删除的值
# print(dic)
# 字典没有remove

# del dic   #  删除整个字典
# print(dic)

# del dic["b"]   #删除指定的键值对
# print(dic)

# dic.clear()    # 清空
# print(dic)     # 删除整个字典中的键值对


# 改:
# dic1 = {"a":"b","C":"c"}
# dic["b"] = "这是值"   # 键在字典中存在就是修改,键在字典中不存在就是增加
# print(dic)

# dic2 = {1:2,"a":"a1"}
# dic2.update(dic1)   # update括号里的字典级别高
# print(dic2)

# 查:
# 字典的查询只能通过键获取值,不能通过值获取键
# dic = {1:2,"a":"a1"}

# print(dic["c"])  # 如果有键在字典中存在就放回键对应的值,如果不存在就报错
# get  -- 获取
# print(dic.get("c","你不是傻,你个狍子"))
# 获取值的时候可以指定返回的内容,键不存在的时候不报错

# dic = {"a":1}
# dic["a"] += 5
# dic.get("a")
# print(dic)


# dic = {1:2,"a":"a1"}
# for i in dic:   # for循环字典的时候打印的是字典的键
#     print(i,dic[i])


# dic = {"1":1,"2":2,"3":3,"4":4}
# # 删除"2"  2种方式
# dic.pop("2")
# del dic["2"]
# # 添加 "5":5 2种方式
#
# dic.setdefault("5",5)
# dic["5"] = 5
# # 修改: "1":10086
# dic["1"] = 10086
#
# # 查看"3"的值
# dic.get("3",'没有值')
# dic["3"]  # 没有就会报错
# dic = {"1":1,"2":2,"3":3,"4":4}
# li = []
# for key in dic:
#     li.append(key)
# print(li)

# for i in dic.keys():#高仿列表
#     print(i)

# print(type(dic.keys()))   可以for循环,但是不能索引
# dic_li = dic.keys()
# print(dic_li)

dic = {"1":1,"2":2,"3":3,"4":4}
# print(dic.values())


# for i in dic.items():
#     print(i)

# 解构
# a = 1
# b = 2
# print("is a",id(a))
# print("is b",id(b))
# a,b = b,a
# print("is a",id(a))
# print("is b",id(b))

# a,_,c = "你好啊"
# print(a,c)

# a,b = ("1","2")
# print(a,b)

# a,b = ["4","5"]
# print(a,b)

# a,b = {"a":1,"b":2,}
# print(a,b)

# dic = {"1":1,"2":2,"3":3,"4":4}
# for key,value in dic.items():
#     print(key,value)

# keys,values,items,解构
dic = {"1":1,"2":2,"3":3,"4":4}
# for i in dic:        # 效率高
#     print(i,dic[i])
#
# for k,v in dic.items():
#     print(k,v)

import time
# s = "3"
# s = time.time()
# if s in  dic.keys():   #列表  --   [1,2,3,4,5]   in for i in dic:
#     pass
# print(time.time() - s)

# s1 = time.time()
# for i in dic:
#     if s == i:
#         pass
# print(time.time() - s1)

# 字典是无序的,我现在
dic = {"电脑":15000,"手机":8000,"耳机":4000,"老婆":1111}
# 1 电脑
# 2 手机
# 3 耳机
# 4 老婆

# for i in range(len(dic)):
#     print(i+1)

# count = 1
# for i in dic:
#     print(count,i)
#     count += 1

# li = [1,2,3,4,54]
# for i,k in enumerate(li):  # enumerate 第二个参数默认不写就是0    -- 枚举
#     print(i,k)

# 字典的嵌套:
# dic = {
#     101:{1:["周杰伦","林俊杰"],2:{"汪峰":["国际章",{"前妻1":["熊大","熊二"]},
#                                   {"前妻2":["葫芦娃","木吒"]}]}},
#     102:{1:["李小龙","吴京","李连杰"],2:{"谢霆锋":["张柏芝","王菲"]},
#          3:["alex","wusir","大象","奇奇"]},
#     103:{1:["郭美美","干爹"],2:{"王宝强":{"马蓉":"宋哲"}}},
#     201:{1:["凹凸曼","皮卡丘"],2:{"朱怼怼":{"杨幂":"刘恺威"}}}
# }

# print(dic[101][2]["汪峰"][2]["前妻2"][0])
#['国际章', {'前妻1': ['熊大', '熊二']}, {'前妻2': ['葫芦娃', '木吒']}]
#{'前妻2': ['葫芦娃', '木吒']}
#['葫芦娃', '木吒']

# home1 = dic[102][3][2]
# {1: ['李小龙', '吴京', '李连杰'],
# 2: {'谢霆锋': ['张柏芝', '王菲']},
# 3: ['alex', 'wusir', '大象', '奇奇']}
# print(home1)

# print(dic[103][2]["王宝强"]["马蓉"])

# 字典能干啥?
# 字典是存储大量的数据,字典比列表还有大
# 字典的查找值的时候能够方便,快速
# li = ["a","b","c","d"]
# 字典能够将数据进行关联
# dic = {"a":"b","b":"c","c":"d"}
# 字典比较消耗内存  最长用的数据 : 字符串,列表,字典
# 有明确的对应关系时,推荐使用字典   字典一定要用明白  -- json

# list((1,3,4))  -- 列表
# tuple([1,2,3])  -- 元组

# s = "{'a':1,'b':2}"
# print(dict(s))     目前所学的知识点字典不能转换的
